import { http } from '/@/utils/http';
import type {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  RegisterParams,
  NonceResultModel,
  UserInfoModel,
  UserInfoParams,
  UserParams,
} from './model/userModel';

export function login(params: LoginParams) {
  return http.post<LoginResultModel>({
    url: '/api/web/user/open/login',
    params,
  });
}

export function logout() {
  return http.get({
    url: '/api/web/user/open/logout',
  });
}

export function sendValidateCode(params: { email: string }) {
  return http.post({
    url: '/api/web/user/open/send_validate_code',
    params,
  });
}

export function getNonce(params: { address: string }) {
  return http.post<NonceResultModel>({
    url: '/api/web/user/open/get_nonce',
    params,
  });
}

export function register(params: RegisterParams) {
  return http.post({
    url: '/api/web/user/open/register',
    params,
  });
}

export function updateUser(params: UserParams) {
  return http.post({
    url: '/api/web/user/user/update',
    params,
  });
}

export function getUserInfo() {
  return http.get<GetUserInfoModel>({ url: '/api/web/user/user/info' });
}

export function getAppUserInfo(params: UserInfoParams) {
  return http.get<UserInfoModel>({ url: '/api/app/user/user/info', params });
}

export function followUser(
  user_follow_id: number | undefined,
  is_subscribe: boolean | string | undefined,
) {
  return http.post({
    url: '/api/web/user/user/follow',
    params: {
      user_follow_id,
      is_subscribe,
    },
  });
}
